We present a self-contained description of everything needed to write a program that calculates the CMB power spectrum for the standard model of cosmology (LCDM). This includes the equations used, assumptions and approximations imposed on their solutions, and most importantly the algorithms and programming tricks needed to make the code actually work. The resulting program is compared to CMBFAST and typically agrees to within 0.1% - 0.4%. It includes both helium, reionization, neutrinos and the polarization power spectrum. The methods presented here could serve as a starting point for people wanting to write their own CMB program from scratch, for instance to look at more exotic cosmological models where CMBFAST or the other standard programs can't be used directly.